// packageA/pages/operate/demonstration/demonstration.js
const App = getApp()
// let reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
let reg = /^1[0-9]{10}$/;
import Toast from '../../../weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    follow_form: {
      name: '',
      agent_name: '',
      agent_mobile: '',
      location:'',
    },
    currentIndex: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      ...this.data.follow_form,
    })
  },
  inputOnChange(e) {
    let input = e.currentTarget.dataset.input
    let value = e.detail
    this.setData({
      follow_form: {
        ...this.data.follow_form,
        [input]: value
      },
    })
  },
  sourceuploda() {
    let _this = this
    let { agent_mobile } = _this.data.follow_form
    if (agent_mobile == '') {
      Toast.fail('手机号不能为空')
      return false
    }
    if (!reg.test(agent_mobile)) {
      Toast.fail('手机号不符合要求');
      return false;
    }
    App._post('Building/materialSubmit', this.data.follow_form, function (result) {
      if (result.code === 0) {
        Toast({
          type: 'success',
          message: '提交成功',
          onClose: () => {
            wx.redirectTo({
              url: '../../operate/floor/floor',
            })
          },
        });
      } else {
        Toast.fail(result.msg);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})